package com.example.hj.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by HuangJian on 2020/7/22.
 */
@RestController
@RefreshScope //开启更新功能
public class TestController {

    @Value("${hj.name}")
    private String name;
    @Value("${hj.from}")
    private String from;

    @RequestMapping(value = "/tt")
    public String tt(Model model) {
        System.out.println("---------- ++++++= "+name );
        System.out.println("ttttttt:"+from);
        return "tttttt";
    }

    @Autowired
    private EurekaClient client;

    /**
     * 通过EnableEurekaClient进行服务注册的服务提供方的应用中，也可以通过注入EurekaClient的方式来调用其它服务提供方注册的服务。
     * 这好象不是调用
     * @return
     */
    @RequestMapping("/test")
    public String testClient() {
        InstanceInfo instanceInfo = client.getNextServerFromEureka("eurekaclient-consumer", false);
        String hpu=instanceInfo.getHomePageUrl();
        return hpu;
    }

    @RequestMapping("/user/{id}")
    public String getUser(@PathVariable("id") Long id){
        System.out.println("----------id = " + id);
        return "hello:"+id;
    }

}
